package com.link.base.base.product.service;

import com.link.base.base.product.dao.mybatis.mapper.ProductAttrMapper;
import com.link.base.base.product.model.ProductAttr;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author unknown
 * @date unknown
 * @comments 产品系列或者产品品牌查询，用于弹出框显示
 */
@Service
public class ProductAttrServiceImpl extends BasicServiceImpl<ProductAttr> implements ProductAttrService {

    @Resource
    private ProductAttrMapper productAttrMapper;

    @Override
    public BasicMapper<ProductAttr> getBasicMapper() {
        return productAttrMapper;
    }

    @Override
    public List<ProductAttr> queryByType(ProductAttr productAttr) throws Exception {
        List<ProductAttr> productAttrList = new ArrayList<ProductAttr>();
        ProductAttr productAttrQuery = new ProductAttr();
        productAttrQuery.setGParentType(productAttr.getGParentType());
        List<ProductAttr> productAttrList1 = productAttrMapper.queryFirstAll(productAttrQuery);

        for (ProductAttr productAttrFirst : productAttrList1) {
            productAttrList.add(productAttrFirst);
            productAttrQuery.setParentType(productAttr.getParentType());
            productAttrQuery.setGParentValue(productAttrFirst.getGParentValue());
            List<ProductAttr> productAttrList2 = productAttrMapper.querySecAll(productAttrQuery);
            for (ProductAttr productAttrSec : productAttrList2) {
                productAttrList.add(productAttrSec);
                productAttrQuery.setChildType(productAttr.getChildType());
                productAttrQuery.setParentValue(productAttrSec.getParentValue());
                List<ProductAttr> productAttrList3 = productAttrMapper.queryThirdAll(productAttrQuery);
                for (ProductAttr productAttrThird : productAttrList3) {
                    productAttrList.add(productAttrThird);
                }
            }
        }
        return productAttrList;
    }
}
